<template>
    <div>
        <hd-tab :tabs="tabs"></hd-tab>
        <el-card class="box-card">

            <div slot="header" class="clearfix">
                <span>创建角色</span>
            </div>
            <el-form ref="form" :model="form" label-width="80px">
                <el-form-item label="角色名称">
                    <el-input v-model="form.name" placeholder="角色英文名称"></el-input>
                    <hd-error name="name"></hd-error>
                </el-form-item>
                <el-form-item label="角色标识">
                    <el-input v-model="form.title" placeholder="角色中文标识"></el-input>
                    <hd-error name="title"></hd-error>
                </el-form-item>
            </el-form>

            <el-button type="success" @click="onSubmit" class="mt-3">保存提交</el-button>
        </el-card>
    </div>
</template>

<script>
import tabs from './tabs'

export default {
    route: false,
    props: ['id'],
    data() {
        return {
            tabs,
            form: {}
        }
    },
    async created() {
        if (this.id) {
            this.form = await this.axios.get(`admin/role/${this.id}`);
        }
    },
    methods: {
        async onSubmit() {
            const url = this.id ? `admin/role/${this.id}` : `admin/role`;
            await this.axios[this.id ? 'put' : 'post'](url, this.form)
            this.$router.push({name: 'admin.role.index'})
        }
    }
}
</script>

<style scoped>

</style>
